package com.simplelove.controller;

import com.simplelove.common.Result;
import com.simplelove.entity.MenstrualCycle;
import com.simplelove.service.MenstrualCycleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 月经周期管理控制器
 */
@RestController
@RequestMapping("/api/menstrual-cycles")
public class MenstrualCycleController {
    
    @Autowired
    private MenstrualCycleService menstrualCycleService;
    
    /**
     * 同步月经周期数据
     */
    @PostMapping("/sync")
    public Result<List<MenstrualCycle>> syncMenstrualCycles(
            @RequestParam Long userId,
            @RequestBody List<MenstrualCycle> cycles) {
        try {
            List<MenstrualCycle> result = menstrualCycleService.syncMenstrualCycles(userId, cycles);
            return Result.success("同步成功", result);
        } catch (Exception e) {
            return Result.error("同步失败: " + e.getMessage());
        }
    }
    
    /**
     * 获取月经周期数据
     */
    @GetMapping
    public Result<List<MenstrualCycle>> getMenstrualCycles(@RequestParam Long userId) {
        try {
            List<MenstrualCycle> cycles = menstrualCycleService.getUserMenstrualCycles(userId);
            return Result.success("获取成功", cycles);
        } catch (Exception e) {
            return Result.error("获取失败: " + e.getMessage());
        }
    }
}
